/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.joint.cpf;

import org.joint.lang.StringFormat;

/**
 *
 * @author madmac
 */
public final class CpfFormat {

   private static final String CPF_MASK = "##-###.###.###";

   private CpfFormat() {}

   public static String fromLongToString(long cpf) {
      String cpfNumbers = String.valueOf(cpf);
      String cpfFormat = CPF_MASK;
      for (int i = cpfNumbers.length() -1; i >= 0; i--) {
         char num = cpfNumbers.charAt(i);
         cpfFormat = cpfFormat.replaceFirst("#", String.valueOf(num));
      }
      if (cpfFormat.contains("#")) {
         cpfFormat = cpfFormat.replaceAll("#", "0");
      }
      return StringFormat.inverse(cpfFormat);
   }
}
